import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'home',
    component: () => import('../views/HomeView.vue')
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/LoginView.vue')
  },
  {
    path: '/register',
    name: 'register',
    component: () => import('../views/RegisterView.vue')
  },
  {
    path: '/project',
    name: 'project',
    component: () => import('../views/project.vue')
  },
  {
    path: '/update',
    name: 'update',
    component: () => import('../views/update.vue')
  },
  {
    path: '/index',
    name: 'index',
    component: () => import('../views/MainView.vue'),
    children: [
      {
        path: '/index/home',
        name: 'home',
        component: () => import('../views/home.vue')
      },
      {
        path: '/index/classify',
        name: 'classify',
        component: () => import('../views/classify.vue')
      },
      {
        path: '/index/search',
        name: 'search',
        component: () => import('../views/search.vue')
      },
      {
        path: '/index/analyze',
        name: 'analyze',
        component: () => import('../views/analyze.vue')
      },


    ]
  }
]

const router = new VueRouter({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes
})

// // 挂载路由导航守卫
// router.beforeEach((to, form, next) => {
//   // to将要访问的路径
//   // form从哪个路径跳转来
//   // next放行

//   if (to.path === '/home') return next()
//   if (to.path === '/login') return next()
//   if (to.path === '/register') return next()
//   const tokenStr = window.localStorage.getItem('user_id')
//   console.log(tokenStr);
//   if (!tokenStr) return next('/home')
//   next()
// })

export default router
